package lego.jbv;

import lejos.nxt.*;

public class Car {
	// Commands for the motors. They are in reverse.
	private static final int forward = 2, backward = 1, stop = 3;

	private static MotorPort leftMotor = MotorPort.A;
	private static MotorPort rightMotor = MotorPort.C;

	private Car() {

	}

	public static void stop() {
		leftMotor.controlMotor(0, stop);
		rightMotor.controlMotor(0, stop);
	}

	public static void forward(int leftPower, int rightPower) {
		leftMotor.controlMotor(leftPower, forward);
		rightMotor.controlMotor(rightPower, forward);
	}

	public static void backward(int leftPower, int rightPower) {
		leftMotor.controlMotor(leftPower, backward);
		rightMotor.controlMotor(rightPower, backward);
	}

	public static void drive(int leftPower, int rightPower) {
		if (0 <= leftPower) {
			leftMotor.controlMotor(leftPower, forward);
		}

		else {
			leftMotor.controlMotor(-leftPower, backward);
		}

		if (0 <= rightPower) {
			rightMotor.controlMotor(rightPower, forward);
		}

		else {
			rightMotor.controlMotor(-rightPower, backward);
		}
	}
}
